home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / dd / watchpoints.c < prev   
C/C++ Source or Header  |  1997-09-09  |  4KB  |  182 lines

  1. /*
  2.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  3.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  4.  *    DICE-LICENSE.TXT.
  5.  */
  6. #include    "defs.h"
  7. #include    "dbug_protos.h"
  8.  
  9. // ************************************************************************
  10.  
  11. Prototype WORD        RefreshWatchpoints(WORD maxLines, BOOL fullRefresh);
  12. Prototype void        InitWatchpoints(void);
  13. Local WORD        FindWP(char *expression);
  14. Prototype BOOL        IsWatchpoint(char *expression);
  15. Prototype BOOL        SetWatchpoint(char *expression, ULONG type);
  16. Prototype BOOL        ClearWatchpoint(char *expression);
  17. Prototype BOOL         ShowWatchTitle(BOOL fullRefresh, WORD *count, WORD *maxLines);
  18. // ************************************************************************
  19.  
  20. WP    wpTable[MAXWP];
  21.  
  22. WORD    RefreshWatchpoints(WORD maxLines, BOOL fullRefresh) {
  23.     WORD    count = 0;
  24.     WORD    i, undef;
  25.     ULONG    val;
  26.     BOOL    flag = FALSE;
  27.  
  28.  
  29.     for (i=0; i<MAXWP && maxLines > 0; i++) {
  30.         switch (wpTable[i].type) {
  31.             case WP_UNSET:        
  32.                 break;
  33.             case WP_BYTES:
  34.                 val = ParseExp(wpTable[i].expression, &undef, strlen(wpTable[i].expression));
  35.                 if (undef)
  36.                     ScrPrintf("%-24.24s *UNDEFINED*", wpTable[i].expression);
  37.                 else {
  38.                     WORD    j = (CurDisplay->ds_ScrCols-35)/3;
  39.                     UBYTE    *ps = (UBYTE *)val;
  40.  
  41.                     if (!flag) {
  42.                         flag = ShowWatchTitle(fullRefresh,&count,&maxLines);
  43.                     }
  44.  
  45.                     ScrPrintf("%-24.24s %08X  ", wpTable[i].expression, val);
  46.                     while (j > 0) {
  47.                         ScrPrintf("%02X ", *ps++);
  48.                         --j;
  49.                     }
  50.                 }
  51.                 count++; 
  52.                 Newline(); 
  53.                 maxLines--;
  54.  
  55.                 break;
  56.             case WP_WORDS:
  57.                 val = ParseExp(wpTable[i].expression, &undef, strlen(wpTable[i].expression));
  58.                 if (undef)
  59.                     ScrPrintf("%-24.24s *UNDEFINED*", wpTable[i].expression);
  60.                 else {
  61.                     WORD    j = (CurDisplay->ds_ScrCols-35)/5;
  62.                     UWORD    *ps = (UWORD *)val;
  63.  
  64.                     if (!flag) {
  65.                         flag = ShowWatchTitle(fullRefresh,&count,&maxLines);
  66.                     }
  67.                     ScrPrintf("%-24.24s %08X  ", wpTable[i].expression, val);
  68.                     while (j > 0) {
  69.                         ScrPrintf("%04X ", *ps++);
  70.                         --j;
  71.                     }
  72.                 }
  73.                 count++; Newline(); maxLines--;
  74.                 break;
  75.             case WP_LONGS:
  76.                 val = ParseExp(wpTable[i].expression, &undef, strlen(wpTable[i].expression));
  77.                 if (undef)
  78.                     ScrPrintf("%-24.24s *UNDEFINED*", wpTable[i].expression);
  79.                 else {
  80.                     WORD    j = (CurDisplay->ds_ScrCols-35)/9;
  81.                     ULONG    *ps = (ULONG *)val;
  82.  
  83.                     if (!flag) {
  84.                         flag = ShowWatchTitle(fullRefresh,&count,&maxLines);
  85.                     }
  86.                     ScrPrintf("%-24.24s %08X  ", wpTable[i].expression, val);
  87.                     while (j > 0) {
  88.                         ScrPrintf("%08X ", *ps++);
  89.                         --j;
  90.                     }
  91.                 }
  92.                 count++; 
  93.                 Newline(); 
  94.                 maxLines--;
  95.                 break;
  96.         }
  97.     }
  98.  
  99.     // add a newline to end if at top of screen
  100.     if(flag && !CurDisplay->ds_RegFlag) {
  101.         Newline(); 
  102.             count++;
  103.         maxLines++;
  104.     }
  105.  
  106.     return count;
  107. }
  108.  
  109. void    InitWatchpoints(void) {
  110.     WORD    i;
  111.  
  112.     for (i=0; i<MAXWP; i++) wpTable[i].type = WP_UNSET;
  113. }
  114.  
  115. Local WORD    FindWP(char *expression) {
  116.     WORD    i, undef;
  117.     ULONG    value, value2;
  118.  
  119.     value = ParseExp(expression, &undef, strlen(expression));
  120.     if (undef) return FALSE;
  121.     for (i=0; i<MAXWP; i++) {
  122.         if (wpTable[i].type != WP_UNSET) {
  123.             if (!strcmp(expression, wpTable[i].expression)) return i;
  124.             value2 = ParseExp(wpTable[i].expression, &undef, strlen(wpTable[i].expression));
  125.             if (value == value2) return i;
  126.         }
  127.     }
  128.     return -1;
  129. }
  130.  
  131. BOOL    IsWatchpoint(char *expression) {
  132.     return (FindWP(expression) != -1);
  133. }
  134.  
  135. BOOL    SetWatchpoint(char *expression, ULONG type) {
  136.     WORD    i, undef;
  137.     ULONG    value;
  138.  
  139.     value = ParseExp(expression, &undef, strlen(expression));
  140.     if (undef) return FALSE;
  141.     for (i=0; i<MAXWP; i++) {
  142.         if (wpTable[i].type == WP_UNSET) {
  143.             wpTable[i].type = type;
  144.             strcpy(wpTable[i].expression, expression);
  145.             return TRUE;
  146.         }
  147.     }
  148.     ScrStatus("*** Watchpoint table full!!");
  149.     return FALSE;
  150. }
  151.  
  152. BOOL    ClearWatchpoint(char *expression) {
  153.     WORD    i = FindWP(expression);
  154.     if (i == -1) {
  155.         ScrStatus("*** Watchpoint not in table");
  156.         return FALSE;
  157.     }
  158.     wpTable[i].type = WP_UNSET;
  159.     return TRUE;
  160. }
  161.  
  162.  
  163. BOOL ShowWatchTitle(BOOL fullRefresh, WORD *count, WORD *maxLines) 
  164. {
  165.     if(fullRefresh != -1) {
  166.     if(CurDisplay->ds_RegFlag) {
  167.         Newline(); 
  168.             (*count)++;
  169.         (*maxLines)++;
  170.     }
  171.     }
  172.  
  173.     ScrPlain();
  174.     ScrInverse();
  175.     ScrPuts("WATCHPOINT               ADDRESS   CONTENTS");
  176. //           xxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx  xx
  177.     Newline(); 
  178.     (*count)++;
  179.     (*maxLines)++;
  180.  
  181.     return TRUE;
  182. }